package com.jike.shop.cloud.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jike.shop.cloud.IGoodService;
import com.jike.shop.cloud.common.result.CommonResult;
import com.jike.shop.cloud.dto.goods.GoodsDetailDto;
import com.jike.shop.cloud.dto.goods.GoodsInfoDto;
import com.jike.shop.cloud.req.GoodsListReq;
import com.jike.shop.cloud.req.LockStockReq;
import com.jike.shop.cloud.req.UnlockStockReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodController {
    @Autowired
    private IGoodService goodService;

    @PostMapping("/lockStock")
    public CommonResult<Void> lockStock(@RequestBody LockStockReq req) {
        goodService.lockStock(req);
        return CommonResult.success(null);
    }

    @PostMapping("/unlockStock")
    public CommonResult<Void> unlockStock(@RequestBody UnlockStockReq req) {
        goodService.unlockStock(req);
        return CommonResult.success(null);
    }

    @GetMapping("/list")
    public CommonResult<IPage<GoodsInfoDto>> list(@RequestBody GoodsListReq req) {
        return CommonResult.success(goodService.getList(req));
    }

    @GetMapping("/detail/{goodsId}")
    public CommonResult<GoodsDetailDto> detail(@PathVariable("goodsId") Long goodsId) {
        return CommonResult.success(goodService.detail(goodsId));
    }
}
